package 位运算;

public class 汉明距离3 {
    //https://leetcode.cn/problems/hamming-distance/description/
    public int hammingDistance(int x, int y) {
        int tmpx = x, tmpy = y, sum = 0;
        while (tmpx != 0) {
            int tmp1 = tmpx & -tmpx;
            tmpx &= (tmpx - 1);
            if((tmp1 & y) == 0) sum++;
        }
        while (tmpy != 0) {
            int tmp1 = tmpy & -tmpy;
            tmpy &= (tmpy - 1);
            if((tmp1 & x) == 0) sum++;
        }
        return sum;
    }
}
